package yyy.ab.common.core;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.List;

/**
 * @param <Mapper>
 * @param <T>
 */
public class BaseServiceImpl<Mapper extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<Mapper, T>
        implements BaseService<T> {

    @Override
    public ResultBean create(T entity) {
        boolean save = save(entity);
        return save ? ResultBean.success() : ResultBean.errorMsg("保存失败！");
    }

    @Override
    public ResultBean update(T entity) {
        boolean saveOrUpdate = saveOrUpdate(entity);
        return saveOrUpdate ? ResultBean.success() : ResultBean.errorMsg("保存失败！");
    }

    @Override
    public ResultBean delete(Serializable id) {
        boolean remove = removeById(id);
        return remove ? ResultBean.success() : ResultBean.errorMsg("删除失败！");
    }

    @Override
    public ResultBean deleteAll(List<? extends Serializable> ids) {
        boolean remove = removeByIds(ids);
        return remove ? ResultBean.success() : ResultBean.errorMsg("删除失败！");
    }
}
